home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / pcutils / windows / genesis / include / cppmaths.h < prev    next >
C/C++ Source or Header  |  1995-12-30  |  9KB  |  235 lines

  1. /*------------------------------------------------------------------
  2.             Maths Library
  3.             -------------
  4.  
  5.     Header for C++ interface to basic geometry related maths
  6.     functions
  7.  
  8.     (C) Silicon Dream Ltd 1994
  9.  
  10.   ------------------------------------------------------------------
  11.  
  12. Changes:                        Date:
  13. * Created file                        19/08/94
  14. */
  15.  
  16. #ifndef CPPMATHS
  17. #define CPPMATHS
  18.  
  19. extern "C"
  20. {
  21. #include "maths.h"
  22. }
  23.  
  24. /*
  25.     Four new classes are defined by this header:
  26.  
  27.         Vec    A three element cartesian vector
  28.         Polar    A three element polar vector
  29.         LVec    A four element cartesian vector
  30.         Mat    A 4x4 matrix
  31.  
  32.     The following operations are permitted on these types:
  33.  
  34.     Vector operations:    Description:
  35.     ------------------    ------------
  36.     Vec vec(x, y, z)    Initialise a vector up to three values
  37.     Vec vecA(vecB)        Initialise a vector with another vector
  38.     Vec vec(lvec)        Initialise a vector with a long vector (loses last component)
  39.     ((Vec) lvec)        Convert a long vector to a vector (loses last component)
  40.     Vec vec(pol)        Initialise a vector with a polar vector (conversion performed)
  41.     ((Vec) pol)             Convert a polar vector to a vector (conversion performed)
  42.     vecA+vecB        Add two vectors
  43.     vecA-vecB        Subtract a vector from another
  44.     vec*f            Multiply a vector by a scalar
  45.     vec*mat            Multiply a vector by a matrix
  46.     vec/f            Divide a vector by a scalar
  47.     vecA+=vecB        Add two vectors (overwrite original)
  48.     vecA-=vecB        Subtract a vector from another (overwrite original)
  49.     vec*=f            Multiply a vector by a scalar (overwrite original)
  50.     vec*=mat        Multiply a vector by a matrix (overwrite original)
  51.     vec/=f            Divide a vector by a scalar (overwrite original)
  52.     -vec            Returns the vector inverted
  53.     vecA==vecB        Are two vectors equal?
  54.     vecA!=vecB        Are two vectors not equal?
  55.     vec.Set(x, y, z)    Set a vector's components
  56.     vec.X()            Get x component
  57.     vec.Y()            Get y component
  58.     vec.Z()            Get z component
  59.     vec.Len()        Get length of vector
  60.     vecA.Dot(vecB)        Get dot product of two vectors
  61.     vecA.Cross(vecB)    Get cross product of two vectors
  62.     vec.AddrVec()        Gets address of Vector member (WARNING: Use only to interface to non C++ code)
  63.  
  64.     Long vector operations:    Description:
  65.     -----------------------    ------------
  66.     LVec lvec(x, y, z, w)    Initialise a long vector with up to four values
  67.     LVec lvecA(lvecB)    Initialise a long vector with another long vector
  68.     LVec lvec(vec)        Initialise a long vector with a vector (last component becomes 1.0)
  69.     ((LVec) vec)        Convert a long vector to a vector (last component becomes 1.0)
  70.     lvec*mat        Multiply a long vector with a matrix
  71.     lvec*=mat        Multiply a long vector with a matrix (overwrite original)
  72.     lvecA==lvecB        Are two long vectors equal?
  73.     lvecA!=lvecB        Are two long vectors not equal?
  74.     lvec.Set(x, y, z, w)    Set a long vector's components
  75.     lvec.X()        Get x component
  76.     lvec.Y()        Get y component
  77.     lvec.Z()        Get z component
  78.     lvec.W()        Get w component (homogeneous coordinate)
  79.     lvec.AddrLVec()        Gets address of LongVec member (WARNING: Use only to interface to non C++ code)
  80.  
  81.     Polar operations:    Description:
  82.     -----------------    ------------
  83.     Polar pol(t, p, r)    Initialise a polar with up to three values
  84.     Polar polA(polB)    Initialise a polar with another polar
  85.     Polar pol(vec)        Initialise a polar with a vector (conversion performed)
  86.     ((Polar) vec)        Convert a vector to a polar (conversion performed)
  87.     polA==polB        Are two polars equal?
  88.     polA!=polB        Are two polars not equal?
  89.     pol.Set(t, p, r)    Set a polar's components
  90.     pol.Theta()        Get theta component
  91.     pol.Phi()        Get phi component
  92.     pol.Rho()        Get rho component
  93.     pol.AddrVec()        Gets address of Vector member (WARNING: Use only to interface to non C++ code)
  94.  
  95.     Matrix operations:    Description:
  96.     ------------------    ------------
  97.     Mat mat            Initialise a matrix with the identity matrix
  98.     Mat matA(matB)        Initialise a matrix with another matrix
  99.     Mat mat(XROT, a)    Initialise a matrix with a rotation or scale value (or leave it unset)
  100.     Mat mat(TRANSL, vec)    Initialise a matrix with a translation value (or leave it unset)
  101.     Mat mat(vecPos, vecDir, vecUp) Initialise a matrix by defining a new coordinate system
  102.     matA*matB        Multiply two matricies
  103.     matA*=matB        Multiply two matricies (overwrite original)
  104.     matA==matB        Are two matricies equal?
  105.     matA!=matB        Are two matricies not equal?
  106.     -mat            Compute inverse of matrix (ie. when multiplied by this gives identity)
  107.     mat.Set(f1,..f16)    Sets elements of a matrix
  108.     mat.MoveParent(vec)    Moves coor sys defined by matrix relative to its parent
  109.     mat.MoveChild(vec)        Moves coor sys defined by matrix relative to itself
  110.     mat.ScaleParent(x, y, z) Scale coor sys defined by matrix relative to its parent
  111.     mat.ScaleChild(x, y, z)    Scale coor sys defined by matrix relative to its own origin
  112.     mat.XRotParent(a)    Rotates coor sys defined by matrix about parents x axis
  113.     mat.XRotChild(a)    Rotates coor sys defined by matrix about its own x axis
  114.     mat.YRotParent(a)    Rotates coor sys defined by matrix about parents y axis
  115.     mat.YRotChild(a)    Rotates coor sys defined by matrix about its own y axis
  116.     mat.ZRotParent(a)    Rotates coor sys defined by matrix about parents z axis
  117.     mat.ZRotChild(a)    Rotates coor sys defined by matrix about its own z axis
  118.     mat.ReverseX()        Reverses direction of x axis of coor sys defined by matrix
  119.     mat.ReverseY()        Reverses direction of y axis of coor sys defined by matrix
  120.     mat.ReverseZ()        Reverses direction of z axis of coor sys defined by matrix
  121.     mat.AddrMat()        Gets address of Matrix member (WARNING: Use only to interface to non C++ code)
  122. */
  123.  
  124. class Vec                    // vec
  125.     {
  126.     friend class LVec;
  127.     friend class Polar;
  128.     friend class Mat;
  129.     public:
  130.         _cppdyn Vec (float fX=0.0, float fY=0.0, float fZ=0.0);
  131.         _cppdyn Vec (Vec &vecOther);
  132.         _cppdyn Vec (LVec &lvec);
  133.         _cppdyn Vec (Polar &pol);
  134.         Vec _cppdyn operator+ (Vec &vecOther);
  135.         Vec _cppdyn operator- (Vec &vecOther);
  136.         Vec _cppdyn operator* (float f);
  137.         Vec _cppdyn operator* (Mat &mat);
  138.         Vec _cppdyn operator/ (float f);
  139.         Vec &_cppdyn operator+= (Vec &vecOther);
  140.         Vec &_cppdyn operator-= (Vec &vecOther);
  141.         Vec &_cppdyn operator*= (float f);
  142.         Vec &_cppdyn operator*= (Mat &mat);
  143.         Vec &_cppdyn operator/= (float f);
  144.         Vec _cppdyn operator- ();
  145.         bool _cppdyn operator== (Vec &vecOther);
  146.         bool _cppdyn operator!= (Vec &vecOther);
  147.         Vec &_cppdyn Set (float fX, float fY, float fZ);
  148.         float _cppdyn X ();
  149.         float _cppdyn Y ();
  150.         float _cppdyn Z ();
  151.         float _cppdyn Len ();
  152.         float _cppdyn Dot (Vec &vecOther);
  153.         Vec _cppdyn Cross (Vec &vecOther);
  154.         Vector *_cppdyn AddrVec ();
  155.     private:
  156.         Vector        vec;
  157.     };
  158.  
  159. class LVec                     // lvec
  160.     {
  161.     friend class Vec;
  162.     public:
  163.         _cppdyn LVec (float fX=0.0, float fY=0.0, float fZ=0.0, float fW=1.0);
  164.         _cppdyn LVec (LVec &lvecOther);
  165.         _cppdyn LVec (Vec &vec);
  166.         LVec _cppdyn operator* (Mat &mat);
  167.         LVec &_cppdyn operator*= (Mat &mat);
  168.         bool _cppdyn operator== (LVec &lvecOther);
  169.         bool _cppdyn operator!= (LVec &lvecOther);
  170.         LVec &_cppdyn Set (float fX, float fY, float fZ, float fW);
  171.         float _cppdyn X ();
  172.         float _cppdyn Y ();
  173.         float _cppdyn Z ();
  174.         float _cppdyn W ();
  175.         LongVec *_cppdyn AddrLVec ();
  176. private:
  177.         LongVec        lvec;
  178.     };
  179.  
  180. class Polar                     // pol
  181.     {
  182.     friend class Vec;
  183.     public:
  184.         _cppdyn Polar (float fX=0.0, float fY=0.0, float fZ=0.0);
  185.         _cppdyn Polar (Polar &polOther);
  186.         _cppdyn Polar (Vec &vecOther);
  187.         bool _cppdyn operator== (Polar &polOther);
  188.         bool _cppdyn operator!= (Polar &polOther);
  189.         Polar &_cppdyn Set (float fTheta, float fPhi, float fRho);
  190.         float _cppdyn Theta ();
  191.         float _cppdyn Phi ();
  192.         float _cppdyn Rho ();
  193.         Vector *_cppdyn AddrVec ();
  194.     private:
  195.         Vector        vec;
  196.     };
  197.  
  198. enum    MatType {XROT, YROT, ZROT, SCALE, TRANSL, UNSET};
  199.  
  200. class Mat                     // mat
  201.     {
  202.     friend class Vec;
  203.     friend class LVec;
  204.     public:
  205.         _cppdyn Mat ();
  206.         _cppdyn Mat (Mat &matOther);
  207.         _cppdyn Mat (MatType mt, float f1=1.0, float f2=1.0, float f3=1.0);
  208.         _cppdyn Mat (MatType mt, Vec vec);
  209.         _cppdyn Mat (Vec &vecOrg, Vec &vecAxZ, Vec &vecAxY);
  210.         Mat _cppdyn operator* (Mat &matOther);
  211.         Mat &_cppdyn operator*= (Mat &matOther);
  212.         bool _cppdyn operator== (Mat &matOther);
  213.         bool _cppdyn operator!= (Mat &matOther);
  214.         Mat _cppdyn operator- ();
  215.         Mat &_cppdyn Set (float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16);
  216.         Mat &_cppdyn MoveParent (Vec &vec);
  217.         Mat &_cppdyn MoveChild (Vec &vec);
  218.         Mat &_cppdyn ScaleParent (float fX, float fY, float fZ);
  219.         Mat &_cppdyn ScaleChild (float fX, float fY, float fZ);
  220.         Mat &_cppdyn XRotParent (float fAng);
  221.         Mat &_cppdyn XRotChild (float fAng);
  222.         Mat &_cppdyn YRotParent (float fAng);
  223.         Mat &_cppdyn YRotChild (float fAng);
  224.         Mat &_cppdyn ZRotParent (float fAng);
  225.         Mat &_cppdyn ZRotChild (float fAng);
  226.         Mat &_cppdyn ReverseX ();
  227.         Mat &_cppdyn ReverseY ();
  228.         Mat &_cppdyn ReverseZ ();
  229.         Matrix *_cppdyn AddrMat ();
  230.     private:
  231.         Matrix        mat;
  232.     };
  233.  
  234. #endif            // Do not include this file twice
  235.